﻿#pragma once

#include <stdexcept>
#include <string>

namespace xi
{

namespace details
{

inline void throw_error(const char *filename, int lineno, const char *expr, std::string msg)
{
    std::string info = std::string(filename) + ":\n line " + std::to_string(lineno) + ": expression " +
                       std::string(expr) + " failed: " + std::string(msg) + "\n";
    throw std::runtime_error(info);
}

} // namespace details

} // namespace xi

#if NDEBUG
#define ASSERT_INFO(x, msg) ;
#else
#define ASSERT_INFO(x, msg)                                                                                            \
    do                                                                                                                 \
    {                                                                                                                  \
        if (!(x))                                                                                                      \
            xi::details::throw_error(__FILE__, __LINE__, #x, msg);                                                     \
    } while (0)
#endif